<?php

/*

1 Player Battle Area (battling_1p.php)

*/

$page_title = "1 Player Battle Area";
$rank_check = 1;
include "header.inc.php";

$findBattle = fetch("SELECT * FROM one_player_battles2 WHERE userid = '$userid' AND game = '$game'");
if (!$findBattle[id])
{
	die(header(error("battle_1player.php?game=$game","This fight does not exsist.")));
}

$findEnemy = fetch("SELECT * FROM one_players2 WHERE id = '$findBattle[enemy]' AND game = '$game'");
$findYourPet = fetch("SELECT * FROM user_pets2 WHERE id = '$findBattle[your_pet]' AND game = '$game'");
$findYourSpecies = fetch("SELECT * FROM pets2 WHERE id = '$findYourPet[species]' AND game = '$game'");

if (!$findBattle[status_line]) { $findBattle[status_line] = "The battle has been started!"; }

$percentHealth = ($findYourPet[current_hp] / $findYourPet[max_hp]) * 100;
if ($percentHealth < 35)
{
	$healthLine = "<font color=red>$findYourPet[current_hp]/$findYourPet[max_hp]</font>";
}
if ($percentHealth > 35)
{
	$healthLine = "<font color=orange>$findYourPet[current_hp]/$findYourPet[max_hp]</font>";
}
if ($percentHealth > 75)
{
	$healthLine = "<font color=green>$findYourPet[current_hp]/$findYourPet[max_hp]</font>";
}

$percentHealth2 = ($findBattle[enemy_hp] / $findEnemy[health]) * 100;
if ($percentHealth2 < 35)
{
	$healthLine2 = "<font color=red>$findBattle[enemy_hp]/$findEnemy[health]</font>";
}
if ($percentHealth2 > 35)
{
	$healthLine2 = "<font color=orange>$findBattle[enemy_hp]/$findEnemy[health]</font>";
}
if ($percentHealth2 > 75)
{
	$healthLine2 = "<font color=green>$findBattle[enemy_hp]/$findEnemy[health]</font>";
}

$findEquipped = mysql_query("SELECT * FROM equipped_items2 WHERE pet_id = '$findBattle[your_pet]' AND game = '$game'");
$numEquipped = mysql_num_rows($findEquipped);
$equippedItems = "<table>";
while ($getEquipped = mysql_fetch_array($findEquipped))
{
	$get_item = fetch("SELECT * FROM items2 WHERE id = '$getEquipped[item_id]' AND game = '$game'");
	$y = $x % 5;
	if ($y == 0)
	{
		$equippedItems .= "<tr>";
	}
	$equippedItems .= "<td><p align=center><a href=battle_1p.pro.php?game=$game&action=item&use_item=$getEquipped[id]><img src=$base_url/images/user_images/opg_$game/items/item_$get_item[id].gif><br><b>$get_item[item_name]</b></a></p></td>";
	if ($y == 4)
	{
		$equippedItems .= "</tr>";
	}
	$x++;
}
$equippedItems .= "</table>";

if ($numEquipped == 0)
{
	$equippedItems = "You have no equipped items.";
}

$bottomCell = "

<p align=center>Use an item:</p>
<p align=center>$equippedItems</p>
<p align=center>OR</p>
<p align=center>Use an Attack:</p>
<form action=battle_1p.pro.php?game=$game&action=attack method=post>
<p align=center>
<select name=use_attack><option>Use which attack?
<option value=charge>Charge
<option value=defend>Defend
$attackList
</select>
<input type=submit value=\"Attack!\">
</p>
</form>
</p>

<p align=center>
<a href=battle_1p_run.php?game=$game onClick=\"if ( !confirm ('Are you sure you want to run away from the enemy?') ) { return false; }\">Run from Battle!</a>
</p>

";

if ($findBattle[enemy_hp] <= 0)
{
	$bottomCell = "<p align=center>Congratulations you have defeated $findEnemy[name]! Click <a href=battle_1p_end.php?game=$game>here</a> to end the battle!</p>";
}

if ($findYourPet[current_hp] <= 0)
{
	$bottomCell = "<p align=center>Sorry, you have been defeated by $findEnemy[name]! Click <a href=battle_1p_end.php?game=$game>here</a> to end the battle!</p>";
}

if (($findYourPet[current_hp] <= 0) AND ($findBattle[enemy_hp] <= 0))
{
	$bottomCell = "<p align=center>Double Knockout! No experience will be given for this fight. Click <a href=battle_1p_end.php?game=$game>here</a> to end the battle!</p>";
}

print "$openHTML";

ECHO <<<END
<Center>
<table width=500>

	<tr width=500>
		<td width=250 bgcolor="#009900" height=35>
			<p align=center><FONT SIZE="+2" COLOR="#FFFFFF"><B>Your Pet</B></FONT></p>
		</td>

		<td width=250 bgcolor="#FF0000" height=35>
			<p align=center><FONT SIZE="+2" COLOR="$topAndBottomText"><B>Your Enemy</B></FONT></p>
		</td>
	</tr>

	<tr width=500>
		<td width=250>
			<p align=center>
			<img src=images/user_images/opg_$game/pets/pet_$findYourSpecies[id].gif><br>
			$findYourPet[name]
			</p>

			<p>
			Health: $healthLine<br>
			Level: $findYourPet[level]
			</p>
		</td>
		<td width=250>
			<p align=center>
			<img src=images/user_images/opg_$game/enemies/enemy_$findEnemy[id].gif><br>
			$findEnemy[name]
			</p>

			<p>
			Health: $healthLine2<br>
			Level: $findEnemy[level]
			</p>
		</td>
	</tr>
	<tr>
		<td colspan=2 bgcolor="#F3FFF4">
			<p>$findBattle[status_line]</p>
		</td>
	</tr>
	<tr>
		<td colspan=2>
		$bottomCell
		</td>
	</tr>
</table>
</center>
END;

print "$closeHTML";
?>